import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:kq_flutter_core_widget/utils/toast_util.dart';
import 'package:kq_flutter_widgets/widgets/pullDown/pull_down_menu_simple.dart';
import 'package:kq_flutter_widgets/widgets/pullDown/entity/drop_down_option.dart';
import 'package:kq_flutter_widgets/widgets/titleBar/kq_title_bar.dart';

class KqPullDownMenuSimplePage extends StatefulWidget {
  const KqPullDownMenuSimplePage({super.key});

  @override
  State<KqPullDownMenuSimplePage> createState() =>
      _KqPullDownMenuSimplePageState();
}

class _KqPullDownMenuSimplePageState extends State<KqPullDownMenuSimplePage> {
  List<List<DropDownOption>> list = [];

  updateFirstCol() {
    Future.delayed(
      const Duration(milliseconds: 2000),
      () {
        if (list.isNotEmpty) {
          list[0] = [
            DropDownOption("title11", "titleId1"),
            DropDownOption("title12", "titleId2"),
            DropDownOption("title13", "titleId3"),
            DropDownOption("title14", "titleId4"),
            DropDownOption("title15", "titleId5"),
            DropDownOption("title16", "titleId6"),
          ];
          setState(() {});
        }
      },
    );
  }

  Future<List<List<DropDownOption>>> getTestData() {
    return Future.delayed(const Duration(milliseconds: 500), () {
      return [
        [
          DropDownOption("title11", "titleId1"),
        ],
        [
          DropDownOption("title21", "titleId1"),
          DropDownOption("title22", "titleId2"),
          DropDownOption("title23", "titleId3"),
          DropDownOption("title24", "titleId4"),
          DropDownOption("title25", "titleId5"),
          DropDownOption("title26", "titleId6"),
          DropDownOption("title27", "titleId7"),
          DropDownOption("title28", "titleId8"),
          DropDownOption("title29", "titleId9"),
          DropDownOption("title210", "titleId10"),
          DropDownOption("title211", "titleId11")
        ],
        [
          DropDownOption("title31", "titleId1"),
          DropDownOption("title32", "titleId2"),
          DropDownOption("title33", "titleId3"),
          DropDownOption("title34", "titleId4"),
          DropDownOption("title35", "titleId5"),
          DropDownOption("title36", "titleId6"),
          DropDownOption("title37", "titleId7"),
          DropDownOption("title38", "titleId8"),
          DropDownOption("title39", "titleId9"),
          DropDownOption("title310", "titleId10"),
          DropDownOption("title311", "titleId11")
        ],
        [
          DropDownOption("title41", "titleId1"),
          DropDownOption("title42", "titleId2"),
          DropDownOption("title43", "titleId3"),
        ]
      ];
    });
  }

  @override
  void initState() {
    super.initState();
    getTestData().then((value) {
      list = value;
      setState(() {});

      updateFirstCol();
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: KqHeadBar(
        headTitle: '下拉菜单演示',
        back: () {
          Get.back();
        },
      ),
      body: PullDownMenuSimple(
        listData: list,
        chosenData: [
          "单选1",
          "多选1",
          DropDownOption("多选2", "null"),
          DropDownOption("单选2", "null")
        ],
        callBack: (data, index) {
          KqToast.showNormal(data.title);
        },
        callBackMulti: (data, index) {
          ///返回一组数据
        },
        isMultiChoose: (index) {
          if (index == 2 || index == 1) {
            return true;
          } else {
            return false;
          }
        },
        customRightFilterContent: () {
          return Container(
            width: double.infinity,
            height:1000,
            color: Colors.red,
          );
        },
        saveKeyOnlyForShow: true,
        saveKey: (index) {
          if (index == 2) {
            return "test1";
          } else if (index == 1) {
            return "test2";
          } else if (index == 0) {
            return "test0";
          }
          return null;
        },
      ),
    );
  }
}
